import { tokenToString } from 'typescript'
import {createRouter,createWebHistory,createWebHashHistory} from 'vue-router'
import { userToken } from "@/store/useToken";



/**
 * vue-router    3.x-    vue 2.x
 * vue-router    4.x  -- vue 3.x
 */
const router = createRouter(
    
    {
	// history:createWebHistory(), //有的需要后端特殊处理
	history:createWebHashHistory(), // 不会修改路径
	routes:[
		
		{
			path:'/home',
			redirect:'/'
		},
		{
			path:'/',
			component:()=> import('@/views/Home.vue'),
			children:[
				
				{
					path: '/props',
					component: () => import('@/views/01-props/Father.vue')
				},
				{
					path: '/emit',
					component: () => import('@/views/02-emit/Father.vue')
				},
				{
					path: '/mitt',
					component: () => import('@/views/03-mitt/Father.vue')
				}, {
					path: '/v-model',
					component: () => import('@/views/04-v-model/Father.vue')
				},{
					path:'/attrs',
					component:()=>import('@/views/05-attrs/GrandFather.vue')
				},{
					path:'/refs-parent',
					component:()=>import('@/views/06-refs-parent/Father.vue')
				},{
					path:'/provice-inject',
					component:()=>import('@/views/07-provice-inject/Father.vue')
				},{
					path:'/pinia',
					component:()=>import('@/views/08-pinia/Father.vue')
				},{
					path:'/slot',
					component:()=>import('@/views/09-slot/Father.vue')
				},{
					path:'/shallow',
					component:()=>import('@/views/shallow/index.vue')
				},{
					path:'/readonly',
					component:()=>import('@/views/readonly/index.vue')
				}
			
			]
		},
		{
			path:'/login',
			component:()=> import('@/views/Login.vue')
		}		
	]
}


)

const whiteList = ['/login','/404','/error']

// router.beforeEach((to,from,next)=>{

	
// 	console.log(
// 	  '%c from: ',
// 	  'background-color: #3756d4; padding: 4px 8px; border-radius: 2px; font-size: 14px; color: #fff; font-weight: 700;',
// 	  from 
// 	)


	
// 	console.log(
// 	  '%c to: ',
// 	  'background-color: #3756d4; padding: 4px 8px; border-radius: 2px; font-size: 14px; color: #fff; font-weight: 700;',
// 	  to 
// 	)
	
// 	const tokenStore =  userToken()


// 	if(whiteList.indexOf(to.path) != -1){ //白名单s
// 		next()
// 	}else{
// 		//获取token
// 		if(tokenStore.token){
// 			next()
// 		}else{
// 			next('/login')
// 		}

// 	}


// })

export default router